﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sexybeauty.Core.Inf.Entities.Table;

namespace Sexybeauty.Core.Inf.LogicEntity.Cache
{
    /// <summary>
    /// 参数只包含一个，为用户名
    /// </summary>
    public class MemberCache : IStorable<MemberEntity>
    {
        public MemberCache() { }
        protected override bool ValidateParameter(params string[] keys)
        {
            return keys.Length == 1 && !String.IsNullOrEmpty(keys[0]);
        }
        protected override MemberEntity LoadDataItem(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                string username = keys[0];
                var member = new Member().Get(c => c.UserName == username);
                return new MemberEntity(member);
            }
            return null;
        }
        protected override string BuildKey(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                return String.Format("GetMemberEntity_{0}", keys[0]);
            }
            return string.Empty;
        }
        protected override string BuildKey(MemberEntity data)
        {
            if (data != null && !String.IsNullOrEmpty(data.UserName))
            {
                return BuildKey(data.UserName);
            }
            return string.Empty;
        }

    }
}
